package com.haipumi.servlets.backadmin;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.haipumi.beans.DataGrid;
import com.haipumi.beans.haipumi_reply;
import com.haipumi.biz.IBackTaskReplyBiz;
import com.haipumi.biz.impl.BackTaskReplyBizImpl;
import com.haipumi.servlets.CommonServlet;
import com.haipumi.utils.RequestUtil;

public class BackTaskReplyServlet extends CommonServlet {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 879979291922320410L;
	
	IBackTaskReplyBiz ibtrb=new BackTaskReplyBizImpl();

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String op=null;
		op=request.getParameter("op");
		if(!"".equals(op)&&op!=null){
			if("findAllTaskReply".equals(op)){
				findAllTaskReply(request,response);
			}else if("saveTaskReply".equals(op)){
				saveTaskReply(request,response);
			}else if("editTaskReply".equals(op)){
				editTaskReply(request,response);
			}
		}
		
	}

	private void editTaskReply(HttpServletRequest request,
			HttpServletResponse response) {
		haipumi_reply reply=null;
		PrintWriter out=null;
		try {
			out=response.getWriter();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		reply=RequestUtil.parseRequest(request, haipumi_reply.class);
		haipumi_reply backreply=ibtrb.editReply(reply);
		if(backreply!=null){
			//成功更改
			super.outData(response, backreply);
		}else{
			//改失败
			backreply=ibtrb.findreply(reply.getUid());
			super.outData(response, backreply);
			out.print("alert('更改失败...')");
		}
	}

	private void saveTaskReply(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		
	}

	private void findAllTaskReply(HttpServletRequest request,
			HttpServletResponse response) {
//		List<haipumi_reply>replylist=ibtrb.findAllTaskReply();
//		int r=ibtrb.countTaskReply();
//		DataGrid dg=new DataGrid();
//		dg.setRows(replylist);
//		dg.setTotal(r);
//		super.outData(response, dg);
	}

}
